// https://leetcode-cn.com/problems/compare-version-numbers/
class Solution {
public:
    void getValue(string &s, int &i, int &val) {
        val = 0;
        while (s[i] != '.') val = val * 10 + (s[i++] - '0');
        if (s[i]) ++i;
        return ;
    }

    int compareVersion(string version1, string version2) {
        int i = 0, j = 0, val1, val2;
        while (version1[i] || version2[j]) {
            getValue(version1, i, val1);
            getValue(version2, j, val2);
            if (val1 - val2) return (val1 < val2 ? -1 : 1);
        }
        return 0;
    }
};